package com.itheima.hmshopping.app.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.hmshopping.dubbo.api.PmsProductAttributeCategoryApi;
import com.itheima.hmshopping.entity.PmsProductAttribute;
import com.itheima.hmshopping.entity.PmsProductAttributeCategory;
import com.itheima.hmshopping.util.HmPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class PmsProductAttributeCategoryService {

    @DubboReference
    private PmsProductAttributeCategoryApi pmsProductAttributeCategoryApi;

    /**
     * 分页获取所有商品属性分类
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public HmPage getProductAttributeCategoryList(Integer pageNum, Integer pageSize) {
        Page page = pmsProductAttributeCategoryApi.list(pageNum, pageSize);
        HmPage hmPage = new HmPage();
        //1.设置总页数
        hmPage.setTotalPage(Convert.toInt(page.getPages()));
        //2.查询数据
        hmPage.setList(page.getRecords());
        //3.总页数
        hmPage.setTotal(Convert.toInt(page.getTotal()));
        //4.每页条数
        hmPage.setPageSize(pageSize);
        //5.第几页
        hmPage.setPageNum(Convert.toInt(pageNum));
        return hmPage;
    }


    /**
     * 获取所有商品属性分类及其下属性
     *
     * @return
     */
    public PmsProductAttributeCategory getAttribute() {
        //1.查询全部的商品
        List<PmsProductAttributeCategory> AttrList = pmsProductAttributeCategoryApi.findAllAttribute();
        return null;
    }
}
